home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
game
/
board
/
Crafty-15.19.lha
/
crafty-15.19
/
src
/
epddefs.h
< prev
next >
Wrap
Text File
|
1998-09-13
|
27KB
|
1,017 lines
#if !defined(EPDDEFS_INCLUDED)
# define EPDDEFS_INCLUDED
/*>>> epddefs.h: Extended Position Description definitions */
/* Revised: 1996.06.23 */
/*
Copyright (C) 1996 by Steven J. Edwards (sje@mv.mv.com)
All rights reserved. This code may be freely redistibuted and used by
both research and commerical applications. No warranty exists.
*/
/*
Everything in this source file is independent of the host program.
Requests for changes and additions should be communicated to the author
via the e-mail address given above.
*/
/*
This file was originally prepared on an Apple Macintosh using the
Metrowerks CodeWarrior 6 ANSI C compiler. Tabs are set at every
four columns. Further testing and development was performed on a
generic PC running Linux 1.3.20 and using the gcc 2.7.0 compiler.
*/
/* inclusion telltale */
#if (!defined(_epddefs))
#define _epddefs 1
/* subprogram storage class for non-statics (usually empty definition) */
#define nonstatic
/* a bit */
#define bit 0x01
/* bit positions */
#define bit_00 (bit << 0)
#define bit_01 (bit << 1)
#define bit_02 (bit << 2)
#define bit_03 (bit << 3)
#define bit_04 (bit << 4)
#define bit_05 (bit << 5)
#define bit_06 (bit << 6)
#define bit_07 (bit << 7)
#define bit_08 (bit << 8)
#define bit_09 (bit << 9)
#define bit_10 (bit << 10)
#define bit_11 (bit << 11)
#define bit_12 (bit << 12)
#define bit_13 (bit << 13)
#define bit_14 (bit << 14)
#define bit_15 (bit << 15)
/* bit width constants */
#define nybbW 4
#define byteW 8
/* simple masks */
#define nybbM 0x000f
/* useful types */
typedef void *voidptrT;
typedef unsigned char byteT, *byteptrT;
typedef char *charptrT;
typedef short int siT, *siptrT;
typedef long int liT, *liptrT;
typedef float srT, *srptrT;
typedef double lrT, *lrptrT;
typedef FILE *fptrT;
/* text I/O buffer length */
#define tL 256
/* EPD I/O buffer length */
#define epdL 4096
/* the standard algebraic notation character vector type */
#define sanL 16 /* must be at least 8; extra room for alternatives */
typedef char sanT[sanL];
typedef sanT *sanptrT;
/* SAN style attributes, priority ordered (used for encoding) */
typedef siT ssaT;
#define ssaL 12
#define ssa_nil (-1)
#define ssa_capt 0 /* 5 way: capture indicator */
#define ssa_case 1 /* 2 way: letter case */
#define ssa_chec 2 /* 3 way: checking */
#define ssa_cast 3 /* 5 way: castling */
#define ssa_prom 4 /* 4 way: promoting */
#define ssa_ptar 5 /* 2 way: pawn target rank skip */
#define ssa_chmt 6 /* 4 way: checkmating */
#define ssa_epct 7 /* 2 way: en passant capture */
#define ssa_draw 8 /* 2 way: drawing */
#define ssa_move 9 /* 2 way: movement indicator */
#define ssa_edcf 10 /* 2 way: extra disambiguating character (file) */
#define ssa_edcr 11 /* 2 way: extra disambiguating character (rank) */
/* SAN style vector */
typedef siT ssavT[ssaL];
/* colors (ordering is critical) */
typedef siT cT, *cptrT;
#define cQ 2
#define cL (bit << cQ)
#define rcQ 1
#define rcL (bit << rcQ)
#define c_nil (-1)
#define c_w 0 /* white */
#define c_b 1 /* black */
#define c_v 2 /* vacant */
#define c_x 3 /* extra */
/* pieces (ordering is critical) */
typedef siT pT, *pptrT;
#define pL 8
#define rpL 6
#define p_nil (-1)
#define p_p 0 /* pawn */
#define p_n 1 /* knight */
#define p_b 2 /* bishop */
#define p_r 3 /* rook */
#define p_q 4 /* queen */
#define p_k 5 /* king */
#define p_v 6 /* vacant */
#define p_x 7 /* extra */
/* color piece combinations (ordering is critical) */
typedef siT cpT;
#define cpL 16
#define rcpL 12
#define cp_nil (-1)
#define cp_wp 0 /* white pawn */
#define cp_wn 1 /* white knight */
#define cp_wb 2 /* white bishop */
#define cp_wr 3 /* white rook */
#define cp_wq 4 /* white queen */
#define cp_wk 5 /* white king */
#define cp_bp 6 /* black pawn */
#define cp_bn 7 /* black knight */
#define cp_bb 8 /* black bishop */
#define cp_br 9 /* black rook */
#define cp_bq 10 /* black queen */
#define cp_bk 11 /* black king */
#define cp_v0 12 /* vacant */
#define cp_x0 13 /* extra 0 */
#define cp_x1 14 /* extra 1 */
#define cp_x2 15 /* extra 2 */
/* ranks */
typedef siT rankT;
#define rankM (0x0007)
#define rankQ 3
#define rankL (bit << rankQ)
#define rank_nil (-1)
#define rank_1 0
#define rank_2 1
#define rank_3 2
#define rank_4 3
#define rank_5 4
#define rank_6 5
#define rank_7 6
#define rank_8 7
/* files */
typedef siT fileT;
#define fileM (0x0007)
#define fileQ 3
#define fileL (bit << fileQ)
#define file_nil (-1)
#define file_a 0 /* QR */
#define file_b 1 /* QN */
#define file_c 2 /* QB */
#define file_d 3 /* Q */
#define file_e 4 /* K */
#define file_f 5 /* KB */
#define file_g 6 /* KN */
#define file_h 7 /* KR */
/* location mappings */
#define map_sq(r, f) (((r) << fileQ | (f)))
#define map_file(sq) ((sq) & 0x07)
#define map_rank(sq) ((sq) >> fileQ)
/* squares */
typedef siT sqT, *sqptrT;
#define sqM (0x003f)
#define sqQ (rankQ + fileQ)
#define sqL (bit << sqQ)
#define sq_nil (-1)
#define sq_a1 map_sq(rank_1, file_a)
#define sq_b1 map_sq(rank_1, file_b)
#define sq_c1 map_sq(rank_1, file_c)
#define sq_d1 map_sq(rank_1, file_d)
#define sq_e1 map_sq(rank_1, file_e)
#define sq_f1 map_sq(rank_1, file_f)
#define sq_g1 map_sq(rank_1, file_g)
#define sq_h1 map_sq(rank_1, file_h)
#define sq_a2 map_sq(rank_2, file_a)
#define sq_b2 map_sq(rank_2, file_b)
#define sq_c2 map_sq(rank_2, file_c)
#define sq_d2 map_sq(rank_2, file_d)
#define sq_e2 map_sq(rank_2, file_e)
#define sq_f2 map_sq(rank_2, file_f)
#define sq_g2 map_sq(rank_2, file_g)
#define sq_h2 map_sq(rank_2, file_h)
#define sq_a3 map_sq(rank_3, file_a)
#define sq_b3 map_sq(rank_3, file_b)
#define sq_c3 map_sq(rank_3, file_c)
#define sq_d3 map_sq(rank_3, file_d)
#define sq_e3 map_sq(rank_3, file_e)
#define sq_f3 map_sq(rank_3, file_f)
#define sq_g3 map_sq(rank_3, file_g)
#define sq_h3 map_sq(rank_3, file_h)
#define sq_a4 map_sq(rank_4, file_a)
#define sq_b4 map_sq(rank_4, file_b)
#define sq_c4 map_sq(rank_4, file_c)
#define sq_d4 map_sq(rank_4, file_d)
#define sq_e4 map_sq(rank_4, file_e)
#define sq_f4 map_sq(rank_4, file_f)
#define sq_g4 map_sq(rank_4, file_g)
#define sq_h4 map_sq(rank_4, file_h)
#define sq_a5 map_sq(rank_5, file_a)
#define sq_b5 map_sq(rank_5, file_b)
#define sq_c5 map_sq(rank_5, file_c)
#define sq_d5 map_sq(rank_5, file_d)
#define sq_e5 map_sq(rank_5, file_e)
#define sq_f5 map_sq(rank_5, file_f)
#define sq_g5 map_sq(rank_5, file_g)
#define sq_h5 map_sq(rank_5, file_h)
#define sq_a6 map_sq(rank_6, file_a)
#define sq_b6 map_sq(rank_6, file_b)
#define sq_c6 map_sq(rank_6, file_c)
#define sq_d6 map_sq(rank_6, file_d)
#define sq_e6 map_sq(rank_6, file_e)
#define sq_f6 map_sq(rank_6, file_f)
#define sq_g6 map_sq(rank_6, file_g)
#define sq_h6 map_sq(rank_6, file_h)
#define sq_a7 map_sq(rank_7, file_a)
#define sq_b7 map_sq(rank_7, file_b)
#define sq_c7 map_sq(rank_7, file_c)
#define sq_d7 map_sq(rank_7, file_d)
#define sq_e7 map_sq(rank_7, file_e)
#define sq_f7 map_sq(rank_7, file_f)
#define sq_g7 map_sq(rank_7, file_g)
#define sq_h7 map_sq(rank_7, file_h)
#define sq_a8 map_sq(rank_8, file_a)
#define sq_b8 map_sq(rank_8, file_b)
#define sq_c8 map_sq(rank_8, file_c)
#define sq_d8 map_sq(rank_8, file_d)
#define sq_e8 map_sq(rank_8, file_e)
#define sq_f8 map_sq(rank_8, file_f)
#define sq_g8 map_sq(rank_8, file_g)
#define sq_h8 map_sq(rank_8, file_h)
/* regular board */
typedef union rbU
{
cpT rbm[rankL][fileL]; /* rank/file indexing */
cpT rbv[sqL]; /* square indexing */
} rbT, *rbptrT;
/* nybble board vector */
#define nbL (sqL / (byteW / nybbW))
typedef byteT nbvT[nbL];
/* flanks */
typedef siT flankT;
#define flankL 2
#define flank_nil (-1)
#define flank_k 0 /* kingside */
#define flank_q 1 /* queenside */
/* direction indices */
typedef siT dxT;
#define dxQ 4
#define dxL (bit << dxQ)
#define dx_nil (-1)
#define dx_0 0
#define dx_1 1
#define dx_2 2
#define dx_3 3
#define dx_4 4
#define dx_5 5
#define dx_6 6
#define dx_7 7
#define dx_8 8
#define dx_9 9
#define dx_a 10
#define dx_b 11
#define dx_c 12
#define dx_d 13
#define dx_e 14
#define dx_f 15
/* direction vector displacements */
typedef siT dvT;
#define dv_0 (( 0 * fileL) + 1)
#def